/*
 * Function.cpp
 *
 *  Created on: 2014. 8. 4.
 *      Author: mega
 */

#include <time.h>
#include "../Static.h"
#include "../Function.h"

namespace GuildServer {

time_t
GetMemberScoreDailyInitTime()
{
	/*
	 * 일일 길드원 포인트 초기화 시간
	 * 매일 오전 1시에 초기화 한다.
	 */

	if (true == Static::Instance().GetTest())
	{
		// 테스트는 20분 주기
		time_t initTime = time(NULL);
		struct tm * stInit = localtime(&initTime);

		if (stInit->tm_min >= 0 &&  stInit->tm_min < 20 )
		{
			stInit->tm_min = 0;
		}
		else if (stInit->tm_min >= 20 && stInit->tm_min < 40)
		{
			stInit->tm_min = 20;
		}
		else if (stInit->tm_min >= 40)
		{
			stInit->tm_min = 40;
		}

		stInit->tm_sec	= 0;
		stInit->tm_isdst = 0;

		return mktime(stInit);
	}

	time_t curTime;
	struct tm * stCurrent;

	time(&curTime);

	stCurrent = localtime(&curTime);

	int addSec = 0;

	if (1 > stCurrent->tm_hour)
		addSec = 3600 * 24;

	time_t initTime = curTime - addSec;
	struct tm * stInit = localtime(&initTime);

	stInit->tm_hour		= 1;
	stInit->tm_min		= 0;
	stInit->tm_sec		= 0;
	stInit->tm_isdst	= 0;

	return mktime(stInit);
}


time_t
GetAttendanceCheckTime()
{
	/*
	 * 출석 체크 시간
	 */

	if (true == Static::Instance().GetTest())
	{
		// 테스트는 20분 주기
		time_t initTime = time(NULL);
		struct tm * stInit = localtime(&initTime);

		if (stInit->tm_min >= 0 &&  stInit->tm_min < 20 )
		{
			stInit->tm_min = 0;
		}
		else if (stInit->tm_min >= 20 && stInit->tm_min < 40)
		{
			stInit->tm_min = 20;
		}
		else if (stInit->tm_min >= 40)
		{
			stInit->tm_min = 40;
		}

		stInit->tm_sec	= 0;
		stInit->tm_isdst = 0;

		return mktime(stInit);
	}

	time_t curTime;
	struct tm * stCurrent;

	time(&curTime);

	stCurrent = localtime(&curTime);

	int addSec = 0;

	if (12 > stCurrent->tm_hour)
		addSec = 3600 * 24;

	time_t initTime = curTime - addSec;
	struct tm * stInit = localtime(&initTime);

	stInit->tm_hour		= 12;
	stInit->tm_min		= 0;
	stInit->tm_sec		= 0;
	stInit->tm_isdst	= 0;

	return mktime(stInit);
}

int
GetGuildExposureStatus(int exposure, std::string & password)
{
	/*
	 * exposure : 0(비노출), 1(노출), 2(노출 + 암호필요)
	 */

	if (1 == exposure && 0 < password.length())
	{
		return 2;
	}

	return exposure;
}

} /*GuildServer*/


